﻿layui.use(['layer', 'form'], function () {
    var layer = layui.layer,
        form = layui.form;
});

$(document).ready(function () {
    loadList();
});

function selectType(obj, type) {
    $(obj).siblings().attr("class", "layui-btn btn-gray");
    if (type == 0) {
        $(obj).removeClass("btn-gray");
        $(obj).addClass("btn-delete");
        $("#tbSearchType").val("");
    } else if (type == 1) {
        $(obj).removeClass("btn-gray");
        $(obj).addClass("btn-edit");
        $("#tbSearchType").val("1");
    } else if (type == 2) {
        $(obj).removeClass("btn-gray");
        $("#tbSearchType").val("2");
    }
    search();
}

function search() {
    var queryParams = {
        "s_0_NoticeTitle|": $('#tbKey').val(),
        "searchType": $("#tbSearchType").val()
    };
    $.extend(true, _table.InitOptions.params, queryParams); //分页带查询参数
    _table.reload();
}

function view(id) {
    app.set('/Business/Notice/Notice.ashx', {
        ActionType: 'ReadNotice',
        GUID: id
    }, function (data) {
        if (data.success) {
            window.top.loadUnReadNoticeList();
            _table.reload();
        }
        layer.open({
            title: "查看通知",
            type: 2,
            area: ["900px", "600px"],
            scrollbar: false,
            content: "/Business/Notice/NoticeViewDetails.aspx?GUID=" + id
        });
    });
}

function loadList() {
    _table.init({
        elem: '#table',
        url: 'Notice.ashx',
        contentType: "application/x-www-form-urlencoded", /**支持跨域**/
        pageSize: 15, //单页记录数
        striped: false, //是否显示行间隔色
        checkboxHeader: true,
        singleSelect: false,
        params: {
            PostType: 'list',
            ActionType: 'UnReadNotice',
            rmd: Math.random()
        }
    });
}

//格式化序号
function formatterNum(value, row, index) {
    //获取每页显示的数量
    var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
    //获取当前是第几页
    var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
    //返回序号，注意index是从0开始的，所以要加上1
    return (pageSize * (pageNumber - 1) + index + 1);
}

function formatterOperationMenu(value, row, index) {
    var acthtml = '';
    acthtml += '<a onclick="view(\'' + row.GUID + '\')"> 查看 </a>';
    return acthtml;
}
